
<div class="container">
	
	<!-- Title -->
	<div class="page-header">
		<h1>
			<?=ucfirst($object)?> <? if ($form): ?> <?=$form?> <? else: ?> <?=$action?> <? endif; ?>
			<!--<small>Some cool stuff about something.</small>-->
		</h1>
	</div>
	
	
	<!-- Alerts -->
	
	<? if ($alerts): ?>
	
		<? foreach($alerts as $alert): ?>
		
			<div class="alert-message <? if ($alert['success']): ?> success <? else: ?> error <? endif; ?>">
				
				<a class="close" href="#">&#215;</a>
				
				<p><strong>Item <?=$alert['id']?>:</strong> <?=$alert['message']?>.</p>
				
			</div>
		
		<? endforeach; ?>
		
	<? endif; ?>
	
	
	
	
	<? if ($action == 'browse'): ?>
	
		<!-- Search -->
		
		<div data-content="search" class="hide">
			
			<form action="<?=$route?>/<?=$object?>/" method="post">
				
				<? foreach($columns as $column): ?>
				
					<? if (!$column['hide']):?>
					
						<div class="clearfix">
							
							<label><?=$column['alias']?></label>
							
							<div class="input">
									
								<!-- Input for regular fields -->
					
								<p id="<?=$column['field']?>">
								
									<input name="search[<?=$column['field']?>]" type="text" value="<?=$filters[$column['field']]['value']?>"/>
							
								</p>
						
							</div>
							
						</div>
						
					<? endif; ?>
				
				<? endforeach; ?>
				
				<div class="actions">
				
					<button class="btn primary" name="action" value="search"><?=__("Search", "en")?></button> <a href="<?=$route?><?=$object?>/" class="btn"><?=__("Cancel", "en")?></a>
				
				</div>
				
			</form>
			
			<hr>
			
		</div>
	
		<form action="<?=$route?>/<?=$object?>/" method="post">
		
			<input type="hidden" name="url" value="<?=$route?>/<?=$object?>/">
			
			<div class="clearfix">
			
				<!-- Actions -->
				
				<? if ($all_access || $acl['add']): ?><a href="<?=$acl['add']?>" class="btn primary"><?=__("Add", "en")?></a><? endif; ?>
				<? if ($all_access || $acl['update']): ?><button class="btn disabled" disabled name="action" data-role="action" value="edit"><?=__("Edit", "en")?></button><? endif; ?>
				<? if ($all_access || $acl['delete']): ?><button class="btn disabled" disabled name="action" data-role="action" value="delete"><?=__("Delete", "en")?></button><? endif; ?>
				
				<!-- Links -->
				
				<a data-toggle="search" class="lnk right"><?=__("Search", "en")?></a>
				
			</div>
			
			<!-- Filters -->
			
			<? if ($filters): ?>
			
				<ul class="unstyled horizontal clearfix">
				
					<? foreach ($filters as $filter): ?>
					
						<? if (!$filter['hide']): ?>
					
							<li><strong><?=$filter['column']?></strong> <?=$filter['value']?> <a title="Remove filter" href="<?=$route?>/<?=$object?>/list/<?=$filter['clean']?>">&#x2718;</a> </li>
						
						<? endif; ?>
					
					<? endforeach; ?>
				
				</ul>
			
			<? endif; ?>
			
			<? if ($items_list['data']): ?>
			
			
			<!-- List of items -->
		
			<table class="zebra-striped selectable" id="table">
			
				<thead>
				
					<tr>
					
						<th><input type="checkbox" data-action="selectall"></th>
						<? foreach($columns as $column): ?>
							<? if (!$column['hide']):?>
								<th>
									<a href="<?=$route?>/<?=$object?>/list/<?=$uri['order']?>order:<?=$column['table']?>.<?=$column['field']?>|<? if(($column['table'].'.'.$column['field'] == $order[0]) && ($order[1] == 'asc')): ?>desc<? else: ?>asc<? endif; ?>/">
										<?=$column['alias']?>
									</a>
								</th>
							<? endif; ?>
						<? endforeach; ?>
					
					</tr>
				
				</thead>
				
				<tfoot>
				
					<tr>
					
						<th><input type="checkbox" data-action="selectall"></th>
						<? foreach($columns as $column): ?>
							<? if (!$column['hide']):?>
								<th>
									<a href="<?=$route?><?=$object?>/list/<?=$uri['order']?>order:<?=$column['table']?>.<?=$column['field']?>|<? if(($column['table'].'.'.$column['field'] == $order[0]) && ($order[1] == 'asc')): ?>desc<? else: ?>asc<? endif; ?>/">
										<?=$column['alias']?>
									</a>
								</th>
							<? endif; ?>
						<? endforeach; ?>
					
					</tr>
				
				</tfoot>
			
				<tbody>
			
					<? foreach($items_list['data'] as $id => $item): ?>

						<tr>
							<td><input type="checkbox" name="id[]" value="<?=$item[$key]?>"></td>
							<? foreach($columns as $column): ?>
								<? if (!$column['hide']):?>
									<td>
										<? if($all_access || $acl['detail']): ?><a href="<?=$acl['detail']?><?=$item[$key]?>"><? endif; ?>
											<?=$item[$column['field']]?>
										<? if($all_access || $acl['detail']): ?></a><? endif; ?>
									</td>
								<? endif; ?>
							<? endforeach; ?>
						</tr>

					<? endforeach; ?>
				
				</tbody>
			
			</table>
	
			<? else: ?>
			
				<div class="clear"><?=__("No items found.", "en")?></div>
			
			<? endif; ?>
		
		</form>
		
		<!-- paging -->
		
		<? if (!CONFIG_LIST_PAGINATION_HIDE || $paging['records'] > $params['limit']): ?>
		
			<div data-role="tableinfo" class="clearfix">
				
				<div class="inline"><?=__("From", "en")?> <?=$paging['from']?> <?=__("to", "en")?> <?=$paging['to']?> <?=__("of", "en")?> <?=$paging['records']?></div>
				
				<div class="right">
				
					<ul class="unstyled horizontal paginate">
					
						<? foreach ($paging['buttons'] as $button): ?>
						
							<li <? if ($button['number'] == $paging['current']): ?> class="active" <? endif; ?> ><a href="<?=$route?>/<?=$object?>/<?=$action?>/<?=$button['url']?>"><?=$button['text']?></a></li>
						
						<? endforeach; ?>
					
					</ul>
				
				</div>
				
			</div>
		
		<? endif; ?>
	
	<? endif; ?>
	
	
	
	
	<? if ($action == 'details'): ?>
	
		<? if ($all_access || $acl['update']): ?><a href="<?=$acl['update']?>" class="btn"><?=__("Edit", "en")?></a><? endif; ?>
		<? if ($all_access || $acl['delete']): ?><a href="<?=$acl['delete']?>" class="btn"><?=__("Delete", "en")?></a><? endif; ?>
		
		<!-- paging -->
		
		<div class="right">
		
			<ul class="unstyled horizontal paginate">
			
				<? foreach ($paging['buttons'] as $button): ?>
				
					<? if ($button['number']): ?>
				
						<li><a href="<?=$route?>/<?=$object?>/<?=$action?>/id:<?=$button['number']?>"><?=$button['text']?></a></li>
						
					<? endif; ?>
				
				<? endforeach; ?>
			
			</ul>
		
		</div>
		
		<hr>
	
		<? if ($items): ?>
			
			<dl>
		
				<? foreach($columns as $column) : ?>
				
					<? if ($column != $key): ?>
				
						<dt><?=$column['alias']?></dt>
						
						<dd>
							<?=$item[$column['field']]?>	
						</dd>
					
					<? endif; ?>
				
				<? endforeach; ?>
			
			</dl>
		
		<? endif; ?>
		
		<hr>
		
		<a href="<?=$back?>"><?=__("Back to list", "en")?></a>
	
	<? endif; ?>
	
	
	
	
	
	<? if ($action == 'edit'): ?>
		
		<form action="<?=$route?>/<?=$object?>/" method="post">
		
			<input type="hidden" name="section" value="<?=$object?>">
			
			<input type="hidden" name="action" value="<?=$form?>">
			
			<input type="hidden" name="url" value="<?=$route?>/<?=$object?>/">
			
			<? foreach ($selected['data'] as $item): ?>
				
				<fieldset>			
	
					<? foreach($columns as $column): ?>
					
						<? if ($column['field'] != $key): ?>
						
							<div class="clearfix">
						
								<label><?=$column['alias']?></label>
								
								<div class="input">
								
									<!-- Form types -->
									
										<!-- Text -->
										
										<? if ($column['structure']['input'] == 'text'): ?>
									
											<input type="text" <? if ($column['size']): ?> maxlength="<?=$column['size']?>" <? endif; ?> name="data[<?=$column['field']?>][<?=$item[$key]?>]" value="<?=$item[$column['field']]?>">
										
										<? endif; ?>
									
										<!-- Textarea -->
										
										<? if ($column['structure']['input'] == 'textarea'): ?>
									
											<textarea <? if ($column['size']): ?> maxlength="<?=$column['size']?>" <? endif; ?> name="data[<?=$column['field']?>][<?=$item[$key]?>]"><?=$item[$column['field']]?></textarea>
										
										<? endif; ?>
									
										<!-- Select -->
										
										<? if ($column['structure']['input'] == 'select'): ?>
										
											<? if ($column['join']): ?>
											
												<select name="data[<?=$column['index']?>][<?=$item[$key]?>]">
											
													<? foreach($column['structure']['options'] as $key_opt => $val_opt): ?>
														
														<option value="<?=$key_opt?>" <? if ($item[$column['field']] == $val_opt): ?> selected <? endif; ?> ><?=$val_opt?></option>
													
													<? endforeach; ?>
											
												</select>
										
											<? else: ?>
											
												<select name="data[<?=$column['field']?>][<?=$item[$key]?>]">
												
													<? foreach($column['structure']['options'] as $key_opt => $val_opt): ?>
														
														<option <? if ($item[$column['field']] == $val_opt): ?> selected <? endif; ?> ><?=$val_opt?></option>
													
													<? endforeach; ?>
											
												</select>
										
											<? endif; ?>
											
										<? endif; ?>
										<!-- Calendar -->
										
										<? if ($column['structure']['input'] == 'date'): ?>
										
											<input data-ui="calendar" type="date" name="data[<?=$column['field']?>][<?=$item[$key]?>]" value="<?=$item[$column['field']]?>">
										
										<? endif; ?>
									
								</div>
								
							</div>
						
						<? endif; ?>
						
					<? endforeach; ?>
				
				</fieldset>
				
			<? endforeach; ?>
			
			<? if($form == 'add'): ?><hr><a data-clone="fieldset:last"><?=__("Add more", "en")?></a><? endif; ?>
			
			<div class="actions">
			
				<button type="submit" class="btn primary"><?=__("Save changes", "en")?></button> <a href="<?=$route?>/<?=$object?>/" class="btn"><?=__("Cancel", "en")?></a>
			
			</div>
		
		</form>
	
	<? endif; ?>
	

	
	
	
</div>


<!-- For debug only -->



<hr>

<div class="container">

	<p><a data-toggle="api">Show API details</a></p>
	
	<div data-content="api" class="hide">
	
		<p>State</p>
		<? printer($state); ?>
	
		<p>Items::get params</p>
		<? printer($params); ?>
		
		<p>Items::get answer</p>
		<? printer($api); ?>
		
	</div>
	
</div>

